package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketGoodsVo;
import com.cskaoyan.market.db.domain.MarketOrderVo;
import com.cskaoyan.market.db.domain.MarketRow;
import com.cskaoyan.market.db.mapper.GoodsMapper;
import com.cskaoyan.market.db.mapper.MarketRowMapper;
import com.cskaoyan.market.db.mapper.OrderMapper;
import com.cskaoyan.market.service.AdminStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminStatServiceImpl implements AdminStatService {

    @Autowired
    OrderMapper mapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    MarketRowMapper rowMapper;


    @Override
    public List<MarketOrderVo> order() {
        List<MarketOrderVo> marketOrderVos = mapper.selectOrderByTime();
        return marketOrderVos;
    }

    @Override
    public List<MarketGoodsVo> goods() {
        List<MarketGoodsVo> marketGoodsVos = goodsMapper.selectOrderByTime();
        return marketGoodsVos;
    }

    @Override
    @Transactional
    public Map<String, List<Object>> user() {
        Map<String,List<Object>> map=new HashMap<>();

        // columns
        List<Object> columns=new ArrayList<>();
        columns.add("day");
        columns.add("users");
        map.put("columns",columns);

        // rows
        List<MarketRow> marketRows = rowMapper.selectGroupBy();
        List<Object> rows=new ArrayList<>();
        rows.addAll(marketRows);
        map.put("rows",rows);
        return map;
    }
}
